/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cxhd.dc.tool;

import com.jfinal.plugin.activerecord.Record;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Administrator
 */
public class DbTool {
    
    
      public static String makeInsertSqlInsert(Record re, String tableName,String insert) {
          
        if (re == null) {
            return null;
        }
        Map<String,Object> map = re.getColumns();
        map.remove("morerptId");
      //  System.out.println(map.toString());
        String sql = "";
        StringBuilder sqlHead = new StringBuilder();
        StringBuilder sqlvalue = new StringBuilder();
        int index = 0;
       
        String[] values = new String[map.size()];
        sqlHead.append(insert).append(tableName).append(" (");
        sqlvalue.append(" values (");
        for (String key : map.keySet()) {
            values[index] = map.get(key)==null?null: map.get(key)+"";
            index++;
            if (index == map.size()) {
                sqlHead.append("`").append(key).append("`").append(" )");
                sqlvalue.append(map.get(key) == null ? "null)" : "'" + map.get(key) + "')");
                // map.get(key)==null?"":"";
                // sqlvalue.append("? )");
            } else {
                sqlHead.append("`").append(key).append("`").append(" , ");
                sqlvalue.append(map.get(key) == null ? "null," : "'" + map.get(key) + "',");
                //sqlvalue.append("?,");
            }

        }
        sql = sqlHead.append(sqlvalue).toString();
       
    

        return sql;

    }
}
